<script>
import {
  getOpenId,
  getUserInfo,
  getAliUserInfo,
  loginByAli,
  updateAliUser
} from '@/api'
import { mapMutations } from 'vuex'
export default {
  methods: {
    ...mapMutations(['setOpenId', 'setUserInfo'])
  },
  onLaunch: function() {
    //#ifdef MP-ALIPAY
    my.getAuthCode({
      scopes: 'auth_base',
      success: res => {
        getAliUserInfo(res.authCode)
          .then(result => {
            this.setUserInfo(result)
          })
          .catch(err => {
            this.setUserInfo([])
          })
      }
    })
    //#endif
    // #ifdef MP-WEIXIN
    wx.login({
      success: res => {
        if (res.code) {
          getOpenId(res.code).then(response => {
            this.setOpenId(response.data)
            getUserInfo(response.data)
              .then(res => {
                this.setUserInfo(res.data)
              })
              .catch(err => {
                this.setUserInfo([])
              })
          })
        }
      }
    })
    //#endif
  },
  onShow: function() {},
  onHide: function() {
    console.log('App Hide')
  }
}
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
/*每个页面公共css */
</style>
